<template>
  <div class="play_back" >
    <div class="play_header">
      <div class="title">
        {{  }}直线图回放
      </div>
      <div class="close_btn" @click="()=> emit('close')">
        X
      </div>
    </div>
    <div class="line_main">
      <!-- 直线图组件放在这里 -->
    </div>
    <div class="play_bottom">
      <el-form :model="searchForm" ref="timerRef" :rules="formRules">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item label="开始时间" prop="startTimer">
              <el-date-picker
                v-model="searchForm.startTimer"
                type="datetime"
                value-format="YYYY-MM-DD hh:mm:ss"
                placeholder="选择开始时间"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="结束时间" prop="endTimer">
              <el-date-picker
                v-model="searchForm.endTimer"
                type="datetime"
                value-format="YYYY-MM-DD hh:mm:ss"
                placeholder="选择结束时间"
              />
            </el-form-item>
          </el-col>
          <el-col :span="1">
            <el-button icon="search" @click="searchData"></el-button>
          </el-col>
          <el-col :span="10">
            <el-slider 
              v-model="timer"
              :show-tooltip="false"
              :step="step"
              :marks="marks"
              :disabled="disabled"
            />
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { toNumber } from "lodash"
import { reactive, watch } from "vue"

const props = defineProps({
  routeId:Number
})
const searchForm = ref({
  startTimer:'',
  endTimer:''
})
const formRules = reactive({
  startTimer:[
    {
      required: true,
      message: '开始时间必填',
      trigger: 'blur',
    },
  ],
  endTimer:[
    {
      required: true,
      message: '结束时间必填',
      trigger: 'blur',
    },
  ]
})
const disabled = false
const step = ref(0)
let mockData = ref([])
for (let i = 0; i < 10; i++) {
  mockData.value.push({
    routeId:`index${i}`,
    routeName:`${i}路`
  })
  step.value = 100 / mockData.value.length < 1 ? 1 : toNumber((100 / mockData.value.length))
}

const timerRef = ref(null)
const searchData = async()=>{
  await timerRef.value.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
    } else {
      console.log('error submit!', fields)
    }
  })
}
const timer = ref(0)
const emit = defineEmits(['close'])
const marks = ref()
watch(searchForm,()=>{
  marks.value = {
    0: searchForm.value.startTimer,
    100: searchForm.value.endTimer,
  }
},{
  deep:true
})
</script>

<style lang="scss" scoped>
  .play_back{
    position: fixed;
    display: flex;
    flex-direction: column;
    z-index: 10;
    width: 97vw;
    height: 50vh;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0px 0px 0px 1px rgba(0, 0, 0, 0.9);
    .play_header{
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 20px;
      height: 12%;
      width: 100%;
      border-bottom: 1px solid #e9e9e9;
      cursor: default;
      .title{
        font-size: 18px;
        font-weight: bold;
      }
      .close_btn{
        cursor: pointer;
      }
    }
    .line_main{
      flex: 1;
    }
    .play_bottom{
      padding: 0px 20px;
      height: 13%;
      width: 100%;
      border-top: 1px solid #e9e9e9;
    }
  }
  :deep(.el-input__wrapper){
    background-color: #ffffff !important;
  }
</style>
